import os
import sys
import logging

# 设置日志
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger('model_downloader')

logger.info("开始下载EasyOCR模型")

try:
    import easyocr
    logger.info("初始化EasyOCR...")
    reader = easyocr.Reader(['ch_sim', 'en'], gpu=False, download_enabled=True)
    logger.info("EasyOCR模型下载成功!")
    logger.info("尝试进行一次文本识别测试...")
    
    # 尝试简单识别以确认模型工作正常
    import numpy as np
    test_img = np.zeros((100, 300), dtype=np.uint8)
    result = reader.readtext(test_img)
    logger.info("文本识别测试完成")
    
    logger.info("===== 全部模型下载和测试完成 =====")
    logger.info("现在您可以关闭此窗口并运行服务器")
    
except Exception as e:
    logger.error(f"下载过程中出现错误: {e}")
    logger.error("请检查网络连接或手动下载模型")
